package cn.com.haopy.yue.ai.db.service.hos.impl;


import cn.com.haopy.yue.ai.db.entity.arisk.HOSStorage;
import cn.com.haopy.yue.ai.db.mapper.arisk.HOSStorageMapper;
import cn.com.haopy.yue.ai.db.service.BaseServiceImpl;
import cn.com.haopy.yue.ai.db.service.hos.HOSStorageService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class HOSStorageServiceImpl extends BaseServiceImpl<HOSStorageMapper, HOSStorage> implements HOSStorageService {
    @Override
    public void deleteByKey(String key) {
        LambdaQueryWrapper<HOSStorage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HOSStorage::getKey, key);

        super.remove(queryWrapper);
    }

    @Override
    public HOSStorage findByKey(String key) {
        LambdaQueryWrapper<HOSStorage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HOSStorage::getKey, key);

        return super.getOne(queryWrapper);
    }

    @Override
    public Page<HOSStorage> querySelective(String key, String name, Integer pageNo, Integer size, String sort, String order) {


        QueryWrapper<HOSStorage> queryWrapper = new QueryWrapper<>();

        if (StringUtils.hasText(key)) {
            queryWrapper.lambda().eq(HOSStorage::getKey, key);
        }
        if (StringUtils.hasText(name)) {
            queryWrapper.lambda().like(HOSStorage::getName, name);
        }

        if (StringUtils.hasText(sort) && StringUtils.hasText(order)) {
            queryWrapper.orderBy(true, "asc".equals(order),sort);
        }
        Page<HOSStorage> page = new Page<>(pageNo, size);

        return super.page(page, queryWrapper);
    }
}
